module.exports = function (callback) {

    var websql = require('./websql');

    if(callback==null){
        websql()
        return
    }
    var userdb = new websql({
        DateBaseName: 'webdb',
        //  Version: "<%version%>",
        Description: 'user-db'
    })
    //  webdb.delTable('drive');
    callback = callback || function () {};
 

    userdb.addBlob('drive', [{
        timedb: new Date().getTime(),
        value: '{}',
        key: "1",
        etag: "",
        lms: "-"
    }], 1, true, function () {
        /// userdb.remove('drive', "where 1=1", function () {})
        userdb.remove('drive', "where key='1'", function () {
            callback()
        });
    })
    this.set = function (row, callback) {
        userdb.remove('drive', "where key='" + row.key + "'", function (off, error) {
            userdb.insert('drive', {
                value: typeof row.value == 'object' ? JSON.stringify(row.value) : row.value,
                timedb: new Date().getTime(),
                lms: row.lms,
                key: row.key,
                etag: row.etag
            }, function (row, error) {
                console.log(error + "------")
                callback()
            })
        })
    };
    this.get = function (key, callback) {
        userdb.read('drive', "where key='" + key + "' order by rowid DESC Limit 0,1;", function (rows, error) {
            console.log(error + "------")
            if (rows.length > 0) {
                var row = rows[0];
                var etag = row.etag;
                var ldb = JSON.parse(row.value);
                callback(ldb, etag, row.lms)
            } else {
                callback(null)
            }
        })
    }
    var self = this;
};